package com.sfpay.coreplatform.member.service.proxy.account.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sfpay.coreplatform.account.service.IAccountInfoQueryService;
import com.sfpay.coreplatform.account.service.exception.AccountServiceException;
import com.sfpay.coreplatform.account.valueobject.tmo.AccountVO;
import com.sfpay.coreplatform.member.common.MemberResponseCode;
import com.sfpay.coreplatform.member.service.exception.MemberServiceException;
import com.sfpay.coreplatform.member.service.proxy.account.IAccProxyQueryService;

/**
 * 
 * 
 * 类说明：会员调用账户查询类
 * 
 * 
 * <p>
 * 详细描述：
 * 
 * 
 * @author 313717
 * 
 *         CreateDate: 2012-5-8
 */
@Service
public class AccProxyQueryServiceImpl implements IAccProxyQueryService {
	@Resource
	private IAccountInfoQueryService accQueryService;

	private static Logger logger = LoggerFactory
			.getLogger(AccProxyQueryServiceImpl.class);

	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public Map<Long, AccountVO> findAccountInfo(List<Long> accNoList) throws MemberServiceException 
	{
		if(logger.isDebugEnabled())
		{
			logger.debug("method:findAccountInfo, bacth query account Info,start invoke account,the parameters 's info"
					+ "{accNoList" + accNoList.toString() + "}");
		}

		Map<Long, AccountVO> map = null;
		try 
		{
			map = accQueryService.findAccountInfo(accNoList);
		} 
		catch (AccountServiceException e) 
		{
			logger.error("invoke account findAccountInfo interface ServiceException:", e);
			throw new MemberServiceException(MemberResponseCode.ACCOUNT_SERVICE_EXCEPTION, "account service error " + e.getMessage());
		} 
		catch (Exception e) 
		{
			logger.error("invoke account findAccountInfo interface exception:", e);
			throw new MemberServiceException(MemberResponseCode.HESSIAN_INVOKE_EXCEPTION,
					"invoke account findAccountInfo interface exception", e);
		}
		
		if(logger.isDebugEnabled())
		{
			logger.debug("method:findAccountInfo, bacth query account Info,end invoke account ,"
					+ "{accNoList" + accNoList.toString() + "}");
		}
		return map;
	}

	@Override
	public AccountVO findAccountInfoByAccountNo(Long accNo)	throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:findAccountInfoByAccountNo,start invoke account,the parameters 's info " +
					"{accNo=" + accNo + "}");
		}
		AccountVO accountVO = null;
		try 
		{
			accountVO = accQueryService.findAccountInfoByAccountNo(accNo);
		} 
		catch (AccountServiceException se) 
		{
			logger.error("invoke account findAccountInfoByAccountNo ServiceException:",se);
			throw new MemberServiceException(MemberResponseCode.ACCOUNT_SERVICE_EXCEPTION, "account service error " + se.getMessage());
		} catch (Exception e) 
		{
			logger.error("invoke account findAccountInfoByAccountNo Exception:", e);
			throw new MemberServiceException(MemberResponseCode.HESSIAN_INVOKE_EXCEPTION,
					"invoke account findAccountInfo interface exception", e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:findAccountInfoByAccountNo,end invoke account,the parameters 's info  " +
					"{accNo=" + accNo + "}");
		}
		return accountVO;
	}
}
